home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Image Compression Mgr / Inside Mac ICM Code / icm1.c < prev    next >
Encoding:
Text File  |  1994-12-04  |  1.8 KB  |  72 lines  |  [TEXT/MPS ]

  1. /*
  2.   File:            icm1.c
  3.   Contains:        Picture Compression Functions
  4.   Written by:    DTS and QT Engineering
  5.   Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  6.   Change History (most recent first):
  7.   <1>         12/4/94    khs        changed the format of the file to the new look and feel
  8.   To Do:
  9. */
  10.  
  11.  
  12. // INCLUDE FILES
  13. #include "icm.h"
  14.  
  15.  
  16. // FUNCTIONS
  17. PicHandle GetQTCompressedPict(CGrafPtr port)
  18. {
  19.     long maxCompressedSize = 0;
  20.     Handle compressedDataH = nil;
  21.     Ptr compressedDataP;
  22.     ImageDescriptionHandle imageDescH = nil;
  23.     OSErr theErr;
  24.     PicHandle myPic = nil;
  25.     Rect bounds = port->portRect;
  26.     PixMapHandle myPixMap = port->portPixMap;
  27.     CodecType theCodecType = 'jpeg';
  28.     CodecComponent theCodec = (CodecComponent)anyCodec;
  29.     CodecQ spatialQuality = codecNormalQuality;
  30.     short depth = 0;                            // let ICM choose depth
  31.  
  32.  
  33.     theErr = GetMaxCompressionSize(myPixMap, &bounds, depth, spatialQuality, theCodecType, 
  34.                                     (CompressorComponent)theCodec, &maxCompressedSize);
  35.     if (theErr)
  36.         return nil;
  37.  
  38.     imageDescH = (ImageDescriptionHandle)NewHandle(4);
  39.     compressedDataH = NewHandle(maxCompressedSize);
  40.     if (compressedDataH != nil && imageDescH != nil)
  41.     {
  42.         MoveHHi(compressedDataH);
  43.         HLock(compressedDataH);
  44.         compressedDataP = StripAddress(*compressedDataH);
  45.  
  46.         theErr = CompressImage(myPixMap, &bounds, spatialQuality, theCodecType, imageDescH, 
  47.                                 compressedDataP);
  48.  
  49.         if (theErr == noErr)
  50.         {
  51.             ClipRect(&bounds);
  52.             myPic = OpenPicture(&bounds);
  53.             theErr = DecompressImage(compressedDataP, imageDescH, myPixMap, &bounds, &bounds, 
  54.                                         srcCopy, nil);
  55.             ClosePicture();
  56.         }
  57.         if (theErr || GetHandleSize((Handle)myPic) == sizeof(Picture))
  58.         {
  59.             KillPicture(myPic);
  60.             myPic = nil;
  61.         }
  62.     }
  63.     if (imageDescH)
  64.         DisposeHandle((Handle)imageDescH);
  65.     if (compressedDataH)
  66.         DisposeHandle(compressedDataH);
  67.  
  68.     return myPic;
  69. }
  70.  
  71.  
  72.